public class ReleaseTrack 
{
	//anti-recursion classes
	private static boolean alreadyUpdatedSolution = false;
    public static boolean hasAlreadyUpdatedSolution() 
    {
    	return alreadyUpdatedSolution;
    }
    public static void setAlreadyUpdatedSolution() 
    {
    	alreadyUpdatedSolution = true;
    }
    //end anti-recursion classes
//This class addresses a need to track release across cases, solutions, and ideas

	public static void CaseToSolution(solution[] solutions)
	{
		if (!ReleaseTrack.hasAlreadyUpdatedSolution()) 
		{
			set<Id> solutionIdSet = New set<Id>();
			for (Solution s : solutions)
			{
				if (s.release__c == null)
				{
					solutionIdSet.add(s.Id);	
				}
			}
			If (solutionIdset.size() > 0)	
			{
				CaseSolution[] cs = [select caseid,solutionid from casesolution where solutionid in :solutionIdSet order by CreatedDate asc];
				If (cs.size()>0)
				{
					set<Id> caseIdSet = New set<Id>();
					Map<Id,string> solutionCaseMap = New Map<Id,string>();
					for (Integer x = 0; x < cs.size(); x++) 
					{
						if (solutionCaseMap.containsKey(cs[x].SolutionId)==false)
						{
							caseIdSet.add(cs[x].CaseId);
							solutionCaseMap.put(cs[x].SolutionId,cs[x].CaseId);
						}					
					}
					Map<Id,string> caseReleaseMap = New Map<id, string>();
					for (Case c : [Select Id,Current_Release__c from case where id in :caseIdset])
					{
						caseReleaseMap.put(c.id, c.Current_Release__c);
					}
					list <solution> updateSolutions = New List<solution>();
					for (solution s:[select Id,release__c from solution where id in :solutionCaseMap.keyset()])
					{
						if (caseReleaseMap.get(solutionCaseMap.get(s.id))!=null)
						{
							s.release__c = caseReleaseMap.get(solutionCaseMap.get(s.id));
							updateSolutions.add(s);
						}
					}
					update updateSolutions;
					setAlreadyUpdatedSolution();
				}
			}
		}
	}

}